home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d2
/
symple.arc
/
SYMPLE.C
< prev
next >
Wrap
Text File
|
1986-08-26
|
42KB
|
1,454 lines
/***********************************************************************
* *
* symple.c *
* (c) 1986 by Collin Brendemuehl *
* B Systems *
* 3228 S. Blvd. #171 *
* Edmond OK 73013 *
* (405) 341-7437 *
* All Rights Reserved. *
* Symple is a configurable DOS system manager for MS-DOS. It will *
* allow the user to set up a complex menu system or a simple DOS *
* manager for the benefit of anyone who is tired of learning/teach- *
* ing/typing DOS commands. *
* Symple was written in C and is for use with either Lattice 3.x or *
* Mark Williams C. It was written so that any conversion to/from *
* other compilers is a simple matter. *
* For more information on inexpensive tools from B Systems/Collin *
* Brendemuehl, please register your copy, noncommercial, at $19.95. *
* At the time of registration you will receive a serialized copy *
* of Symple. When a distributed copy of YOUR serial number is *
* registered, I will send you $4.00. Registration also entitles *
* to discounts on my other software packages. *
* Also, please do not violate the spirit of "shareware"--please *
* distribute the software with the Documentation for personal, *
* non-commercial use. A License is available for commercial use, *
* along with source code. Thanks for your assistance. *
***********************************************************************/
#include "symple.h"
main()
{
initialize(); /* initialize the system */
operate(); /* operate Symple */
}
/***********************************************************************/
/* */
/* System Initialization */
/* */
/***********************************************************************/
initialize()
{
up_front(); /* draw the start-up screen */
memory_allocation(); /* allocate memory */
get_cfg("symple.cfg"); /* get the default .cfg file */
cls(); /* clear the screen */
display_setup(); /* setup the initial display */
}
/***********************************************************************/
/* */
/* Up Front */
/* */
/***********************************************************************/
up_front() /* fairly self-explanatory */
{
long ii;
cls(); /* for Lattice C, putsnb should be replaced with printf */
locate( 5,12); putsnb("╔════════╗ ┌──┐ ╔═════╗");
locate( 6,12); putsnb("║ ╔═════╝ │ │ ║ ╔══╝");
locate( 7,12); putsnb("║ ╚═════╗ ┌──┐┌──┐ ┌──────────┐ ┌──────┐ │ │ ║ ╚═╗ ");
locate( 8,12); putsnb("╚═════╗ ║ │ ││ │ │ ┌┐ ┌┐ │ │ ┌┐ │ │ │ ║ ╔═╝ ");
locate( 9,12); putsnb("╔═════╝ ║ │ └┘ │ │ ││ ││ │ │ └┘ │ │ │ ║ ╚══╗");
locate(10,12); putsnb("╚════════╝ └───┐ │ └──┘└──┘└──┘ │ ┌───┘ └──┘ ╚═════╝");
locate(11,12); putsnb(" ┌───┘ │ │ │");
locate(12,12); putsnb(" └──────┘ └──┘");
locate(14,10); putsnb(" Use Free of Charge. Or register Symple for $20.00 for");
locate(15,10); putsnb("non-commercial use. Commercial License available.");
locate(16,34); putsnb("Serial #684F"); /* FIDO in "hex" (so to bark) */
locate(17,34); putsnb("Collin Brendemuehl");
locate(18,34); putsnb("3882 S Blvd #171");
locate(19,34); putsnb("Edmond OK 73013");
locate(20,34); putsnb("(405) 341-7437");
locate(23,0); putsnb("System Manager Plus");
locate(24,0); putsnb("Copyright 1986 by Collin Brendemuehl");
for(ii=0;ii<80000l;ii++);
for(ii=0;ii<80000l;ii++);
for(ii=0;ii<80000l;ii++);
for(ii=0;ii<80000l;ii++);
}
/***********************************************************************/
/* */
/* General Operation Loop */
/* */
/***********************************************************************/
operate()
{
int ii;
do {
fill_window(3,8,3,16,0x70);
locate(3,8);
putsnb("Functions");
while( kbhit()!=TRUE) /* if no key has been hit */
new_time(); /* do a time update */
/* kbhit is OPPOSITE lattice */
ii = getfch(); /* now get a character */
/* a handy little function! */
noftitle(); /* clear title */
switch(ii) /* call execute with proper */
{ /* operation in hand */
case F1: execute(funcommand[0][0]); break;
case F2: execute(funcommand[0][1]); break;
case F3: execute(funcommand[0][2]); break;
case F4: execute(funcommand[0][3]); break;
case F5: execute(funcommand[0][4]); break;
case F6: execute(funcommand[0][5]); break;
case F7: execute(funcommand[0][6]); break;
case F8: execute(funcommand[0][7]); break;
case F9: execute(funcommand[0][8]); break;
case F10: execute(funcommand[0][9]); break;
case SF1: execute(funcommand[1][0]); break;
case SF2: execute(funcommand[1][1]); break;
case SF3: execute(funcommand[1][2]); break;
case SF4: execute(funcommand[1][3]); break;
case SF5: execute(funcommand[1][4]); break;
case SF6: execute(funcommand[1][5]); break;
case SF7: execute(funcommand[1][6]); break;
case SF8: execute(funcommand[1][7]); break;
case SF9: execute(funcommand[1][8]); break;
case SF10: execute(funcommand[1][9]); break;
case AF1: execute(funcommand[2][0]); break;
case AF2: execute(funcommand[2][1]); break;
case AF3: execute(funcommand[2][2]); break;
case AF4: execute(funcommand[2][3]); break;
case AF5: execute(funcommand[2][4]); break;
case AF6: execute(funcommand[2][5]); break;
case AF7: execute(funcommand[2][6]); break;
case AF8: execute(funcommand[2][7]); break;
case AF9: execute(funcommand[2][8]); break;
case AF10: execute(funcommand[2][9]); break;
case CF1: execute(funcommand[3][0]); break;
case CF2: execute(funcommand[3][1]); break;
case CF3: execute(funcommand[3][2]); break;
case CF4: execute(funcommand[3][3]); break;
case CF5: execute(funcommand[3][4]); break;
case CF6: execute(funcommand[3][5]); break;
case CF7: execute(funcommand[3][6]); break;
case CF8: execute(funcommand[3][7]); break;
case CF9: execute(funcommand[3][8]); break;
case CF10: execute(funcommand[3][9]); break;
case PGDN: rotate(); break;
case HOME: display_contents(); break;
default: break;
}
} while(ii!=ESC);
setcsize(1,5);
cls();
locate(0,0);
putsnb("Thank you for using Symple.");
}
noftitle()
{
clear_window(3,8,3,16);
locate(3,8);
putsnb("Functions");
}
/***********************************************************************/
/* */
/* Setup the screen for display */
/* */
/***********************************************************************/
display_setup()
{
cls(); /* clear the screen */
setcsize(14,14); /* get rid of cursor */
borders(); /* draw borders */
titles(); /* display titles */
display_contents(); /* display contents */
}
/***********************************************************************/
/* */
/* Display the Contents on the Screen */
/* */
/***********************************************************************/
display_contents()
{
display_directory(); /* the directory */
display_cfg(); /* the .cfg prompt lines*/
infowindow(); /* the path, drive, etc.*/
time_display(); /* the time and date */
}
/***********************************************************************/
/* */
/* Display the Functions */
/* */
/***********************************************************************/
display_cfg()
{
int i;
static char *sac[4] =
{
" ",
"Shift-",
" Alt-",
" Ctrl-"
};
cfg_window();
for( i=0 ; i<10 ; i++ )
{
locate(funloc[i][0],funloc[i][1]);
putsnb(sac[ilevel]);
locate(funloc[i][0],funloc[i][1]+6);
putsnb(funnames[i]);
locate(funloc[i][0],funloc[i][1]+10);
putsnb(funtitles[ilevel][i]);
}
}
/***********************************************************************/
/* */
/* Display the Titles */
/* */
/***********************************************************************/
titles()
{
locate(1,40 - (strlen(system_title) / 2 ) );
putsnb(system_title);
locate(3,8); putsnb("Functions");
locate(16,24); putsnb("Calculator and System Information");
locate(3,50); putsnb(" Directory ");
}
/***********************************************************************/
/* */
/* Draw the Borders */
/* */
/***********************************************************************/
borders()
{
int i;
locate(0,0); putcnb('┌');
locate(24,0); putcnb('└');
locate(0,78); putcnb('┐');
locate(24,78); putcnb('┘');
for(i=1;i<78;i++)
{
locate(0,i); putcnb('─');
locate(2,i); putcnb('─');
locate(4,i); putcnb('─');
locate(15,i); putcnb('─');
locate(17,i); putcnb('─');
locate(24,i); putcnb('─');
}
for(i=1;i<24;i++)
{
locate(i,0); putcnb('│');
locate(i,78); putcnb('│');
if(i>2 && i<15) {
locate(i,40); putcnb('│'); }
}
locate(2,40); putcnb('┬');
locate(4,40); putcnb('┼');
locate(15,40); putcnb('┴');
locate(2,0); putcnb('├');
locate(4,0); putcnb('├');
locate(15,0); putcnb('├');
locate(17,0); putcnb('├');
locate(2,78); putcnb('┤');
locate(4,78); putcnb('┤');
locate(15,78); putcnb('┤');
locate(17,78); putcnb('┤');
}
/***********************************************************************/
/* */
/* Load the Configuration File */
/* */
/***********************************************************************/
get_cfg(fe_cfg)
char *fe_cfg;
{
int i,j;
FILE *fecfg;
fecfg = fopen(fe_cfg,"r");
fgets(system_title,0x80,fecfg);
for(i=0;i<4;i++)
{
for(j=0;j<10;j++)
{
fgets(funtitles[i][j],0x80,fecfg);
fgets(funcommand[i][j],0x80,fecfg);
funcommand[i][j][strlen(funcommand[i][j])-1]='\0';
}
}
fclose(fecfg);
}
/***********************************************************************/
/* */
/* Allocate Memory for the System */
/* */
/***********************************************************************/
memory_allocation()
{
int i,j;
int strcmp();
dirtag = (char*) malloc(300*sizeof(char));
directory = (char**)malloc(300*sizeof(char*));
for(i=0;i<300;i++)
directory[i] = (char*)malloc(15*sizeof(char));
get_directory("*.*");
for(i=0;i<4;i++)
for(j=0;j<10;j++)
{
funtitles[i][j]=(char*)malloc(20*sizeof(char));
funcommand[i][j]=(char*)malloc(30*sizeof(char));
}
}
/***********************************************************************/
/* */
/* Get the General Directory */
/* */
/***********************************************************************/
get_directory(format)
char *format;
{
dircount=0;
get_dir(format,0);
if(last_dir_format != format)
strcpy(last_dir_format,format);
}
/***********************************************************************/
/* */
/* Get the Directory */
/* */
/***********************************************************************/
get_dir(format,atrib)
char *format;
int atrib;
{
if(dfind(&finfo,format,atrib)==TRUE)
do {
dirtag[dircount] = '-';
strcpy(directory[dircount++],finfo.fnd_name);
} while(dnext(&finfo)==TRUE && dircount <300);
}
/***********************************************************************/
/* */
/* Display the Directory */
/* */
/***********************************************************************/
display_directory()
{
int i;
dir_window();
for( i = 0 ; i < min(dircount,10) ; i++)
{
locate(dirloc[i][0],dirloc[i][1]);
sprintf(temp,"%c %-12s ",dirtag[i],directory[i]);
putsnb(temp);
}
}
/***********************************************************************/
/* */
/* Rotate the Normal Shift Alternate Control Function Keys */
/* */
/***********************************************************************/
rotate()
{
if(++ilevel==4) ilevel=0;
display_cfg();
}
/***********************************************************************/
/* */
/* Function Execution */
/* */
/***********************************************************************/
execute(strcom)
char *strcom;
{
char c;
switch(*strcom)
{
case '1': new_cfg();
break;
case '2': program_tags(1);
break;
case '3': delete_tags();
break;
case '4': copy_tags();
break;
case '5': print_tags();
break;
case '6': un_tags();
break;
case '7': new_dir(strcom+1);
break;
case '8': manual_entry("Change to Directory: ");
chdir(manual_command);
break;
case '9': manual_entry("Remove Directory: ");
rmdir(manual_command);
break;
case '0': manual_entry("Create Directory: ");
mkdir(manual_command);
break;
case '=': manual_entry("Manual DOS Command: ");
cls();
system(manual_command);
putsnb("Hit <RETURN> to return to Symple");
c = getcnb();
cls();
display_setup();
break;
case '/': program_tags(0);
break;
case '+': calculator();
break;
case '!': mkdir(strcom+1);
break;
case '@': chdir(strcom+1);
break;
case '%': rmdir(strcom+1);
break;
case '*': chdrive(strcom+1);
break;
case '&': manual_entry("Drive Selected: ");
chdrive(manual_command);
break;
case '^': get_cfg(strcom+1);
display_cfg(0);
break;
default : cls();
setcsize(1,5);
system(strcom);
setcsize(14,14);
putsnb("Hit <RETURN> to return to Symple");
c = getcnb();
cls();
display_setup();
}
}
/***********************************************************************/
/* */
/* Set up the Information Window */
/* */
/***********************************************************************/
infowindow()
{
text_window();
locate(18,10);
disk_space();
sprintf(temp,"%10ld Drive Size %10ld Free Space %2ld%% Unused",
disk_size, free_space, disk_slack);
putsnb(temp);
locate(19,10);
putsnb("Current Path : ");
locate(19,25);
current_drive();
putcnb('A' + REGS.HREG.r_al); putsnb(":\\");
getpath();
locate(19,28);
putsnb((char*)REGS.WREG.r_si);
locate(20,10);
putsnb("PgDn Shows more Function Key Options");
locate(21,10);
putsnb("Esc Exits to DOS, HOME Rewrites Screen Contents.");
}
/***********************************************************************/
/* */
/* A Simple Calculator */
/* */
/***********************************************************************/
calculator()
{
text_window();
dispstack();
calc_input();
infowindow();
}
/***********************************************************************/
/* */
/* Display the Stack */
/* */
/***********************************************************************/
dispstack()
{
int i;
for(i=0;i<=5;i++)
{
locate(18+i,8);
sprintf(temp,"%c. %15.6lf",'1'+i,calcstack[i]);
putsnb(temp);
}
}
/***********************************************************************/
/* */
/* Calculator Entry and Operations */
/* */
/***********************************************************************/
calc_input()
{
static double rval = 0.0;
static double lval = 0.0;
static double mval = 0.0;
static char ul[] = "_______________";
char calca[16];
char calcb[16];
char formula;
fill_window(16,24,16,33,0x70);
locate(16,24);
putsnb("Calculator");
locate(21,40); putsnb("...............");
locate(22,40); putsnb(ul);
locate(23,40); putsnb("+ - * /");
for(;;)
{
locate(22,40);
sprintf(temp,"%15.6lf",mval);
putsnb(temp);
locate(19,40);
putsnb(ul);
locate(20,40);
putsnb(ul);
/* 123456789012345 */
locate(19,38);
putcnb('>');
locate(19,40);
while( kbhit()!=TRUE)
{
new_time();
locate(19,40);
}
locate(19,40);
gets(calca);
locate(19,38);
putcnb(' ');
if(strlen(calca)==0) break;
if(calca[0]=='P')
{
switch(calca[1])
{
case '1': lval = calcstack[0]; break;
case '2': lval = calcstack[1]; break;
case '3': lval = calcstack[2]; break;
case '4': lval = calcstack[3]; break;
case '5': lval = calcstack[4]; break;
case '6': lval = calcstack[5]; break;
}
}
else
if(calca[0]=='S')
{
switch(calca[1])
{
case '1': calcstack[0] = mval; break;
case '2': calcstack[1] = mval; break;
case '3': calcstack[2] = mval; break;
case '4': calcstack[3] = mval; break;
case '5': calcstack[4] = mval; break;
case '6': calcstack[5] = mval; break;
}
dispstack();
continue;
}
else lval = atof(calca);
locate(19,40);
sprintf(temp,"%15.6lf",lval);
putsnb(temp);
locate(20,38);
putcnb('>');
locate(20,40);
while( kbhit()!=TRUE)
{
new_time();
locate(20,40);
}
locate(20,40);
gets(calcb);
locate(20,38);
putcnb(' ');
if(strlen(calcb)==0) rval = 0.0;
else
if(calcb[0]=='P')
{
switch(calcb[1])
{
case '1': rval = calcstack[0]; break;
case '2': rval = calcstack[1]; break;
case '3': rval = calcstack[2]; break;
case '4': rval = calcstack[3]; break;
case '5': rval = calcstack[4]; break;
case '6': rval = calcstack[5]; break;
}
}
else rval = atof(calcb);
locate(20,40);
sprintf(temp,"%15.6lf",rval);
putsnb(temp);
locate(23,38);
putcnb('>');
do {
locate(23,48);
formula = getcnb();
} while(formula != '+' && formula != '-' &&
formula != '*' && formula != '/' );
switch(formula)
{
case '+': mval = rval + lval; break;
case '-': mval = rval - lval; break;
case '*': mval = rval * lval; break;
case '/': mval = rval / lval; break;
}
locate(23,38);
putcnb(' ');
}
clear_window(16,24,16,33);
locate(16,24);
putsnb("Calculator");
}
/***********************************************************************/
/* */
/* Get the new Directory Listing */
/* */
/***********************************************************************/
new_dir(dstring)
char *dstring;
{
get_directory(dstring);
display_directory();
}
/***********************************************************************/
/* */
/* Tag Files/Scan Files */
/* */
/***********************************************************************/
program_tags(mode)
int mode;
{
int i,j,k;
fill_window(3,50,3,60,0x70);
locate(3,50);
putsnb(" Directory ");
text_window();
locate(20,20);
if(mode==1)
putsnb("T)ag U)ntag ");
putsnb("UP-Prev DOWN/<Space>-Next ESC-Quit HOME-First");
dir_window();
/***********************************/
/* Tag Prompt */
/***********************************/
locate(dirloc[0][0],dirloc[0][1]-2);
putcnb('>');
/***********************************/
/* Tag Prompt */
/***********************************/
for( i = 0 ; i < min(dircount,10) ; i++ )
{
locate(dirloc[i][0],dirloc[i][1]);
sprintf(temp,"%c %-12s ",dirtag[i],directory[i]);
putsnb(temp);
}
for(i=0;i<dircount;i++)
{
/***********************************/
/* User Entry */
/***********************************/
userloop:
while( kbhit() != TRUE)
new_time();
j = getfch();
/***********************************/
/* User Options */
/***********************************/
switch(j)
{
case UP :
i -= 2;
if(i == -2)
i = -1;
else dir_window_down();
locate(dirloc[0][0],dirloc[0][1]);
sprintf(temp,"%c %12s",
dirtag[i+1],directory[i+1]);
putsnb(temp);
break;
case DOWN :
case ' ' :
dir_window_up();
if(i == dircount) i = 0;
if(i+10 < dircount)
{
locate(dirloc[9][0],dirloc[9][1]);
sprintf(temp,"%c %12s",
dirtag[i+10],directory[i+10]);
putsnb(temp);
}
break;
case 't' :
case 'T' :
if(mode==1)
{
dirtag[i] = 'T';
locate(dirloc[0][0],dirloc[0][1]);
putcnb(dirtag[i]);
goto userloop;
}
break;
case 'u' :
case 'U' :
if(mode==1)
{
dirtag[i] = '-';
locate(dirloc[0][0],dirloc[0][1]);
putcnb(dirtag[i]);
goto userloop;
}
break;
case HOME :
dir_window();
for( k = 0 ; k < min(dircount,10) ; k++ )
{
locate(dirloc[k][0],dirloc[k][1]);
sprintf(temp,"%c %12s",
dirtag[k],directory[k]);
putsnb(temp);
}
i = -1;
continue;
case ESC :
locate(dirloc[0][0],dirloc[0][1]-2);
putcnb(' ');
clear_window(3,50,3,60);
locate(3,50);
putsnb(" Directory ");
locate(20,8);
clrline();
display_directory();
infowindow();
return;
default: i--;
}
/***********************************/
/* Loop Continuation */
/***********************************/
if(i==dircount) i = -1;
}
clear_window(3,50,3,60);
locate(3,50);
putsnb(" Directory ");
locate(20,8);
clrline();
display_directory();
infowindow();
}
/***********************************************************************/
/* */
/* Display the File Tag Status */
/* */
/***********************************************************************/
display_entry(table_entry)
int table_entry;
{
if(table_entry<13)
{
locate(dirloc[table_entry][0],dirloc[table_entry][1]-9);
putcnb(dirtag[table_entry]);
}
}
/***********************************************************************/
/* */
/* Delete all tagged files */
/* */
/***********************************************************************/
delete_tags()
{
int i;
locate(20,8); clrline();
locate(20,8);
putsnb("Deleting Files : ");
for(i=0;i<dircount;i++)
{
if(dirtag[i] == 'T')
{
locate(20,25);
putsnb(directory[i]);
putsnb(" ");
unlink(directory[i]);
}
}
get_directory();
display_directory();
}
/***********************************************************************/
/* */
/* Backup the Tagged Files */
/* */
/***********************************************************************/
copy_tags()
{
int i;
manual_entry("Destination Directory:");
for(i=0;i<dircount;i++)
{
if(dirtag[i] == 'T')
{
strcpy(temp,"copy ");
strcat(directory[i]);
strcat(temp," ");
strcat(temp,manual_command);
strcat(temp," > NUL:");
system(temp);
}
}
}
/***********************************************************************/
/* */
/* Send Tagged Files to the Printer */
/* */
/***********************************************************************/
print_tags()
{
int i;
for(i=0;i<dircount;i++)
{
if(dirtag[i] == 'T')
{
strcpy(temp,"pr ");
strcat(temp,directory[i]);
system(temp);
}
}
}
/***********************************************************************/
/* */
/* Untag the tagged files */
/* */
/***********************************************************************/
un_tags()
{
int i;
for(i=0;i<300;i++)
dirtag[i] = '-';
}
/***********************************************************************/
/* */
/* Get the new "config" File */
/* */
/***********************************************************************/
new_cfg()
{
FILE *tmfile;
do {
manual_entry("New Config File: ");
if(strlen(manual_command)==0) return;
tmfile=fopen(manual_command,"r");
}while(tmfile==0);
fclose(tmfile);
get_cfg(manual_command);
display_cfg(0);
}
/***********************************************************************/
/* */
/* Manual Command Line Entry. */
/* */
/***********************************************************************/
manual_entry(prompt)
char *prompt;
{
locate(22,8);
putsnb(prompt);
while( kbhit()!=TRUE)
{
new_time();
locate(22,8);
}
locate(22,8+strlen(prompt)+1);
setcsize(1,5);
gets(manual_command);
setcsize(14,14);
locate(22,8);
clrline();
locate(22,8);
}
/***********************************************************************/
/* */
/* Clear the contents of a line. */
/* */
/***********************************************************************/
clrline()
{
putsnb(" ");
}
/***********************************************************************/
/* */
/* Clear Function Window */
/* */
/***********************************************************************/
cfg_window()
{
clear_window(5,1,14,39);
}
/***********************************************************************/
/* */
/* Directory Window UP */
/* */
/***********************************************************************/
dir_window_up()
{
scroll_window_up(5,41,14,74);
}
/***********************************************************************/
/* */
/* Clear directory Window */
/* */
/***********************************************************************/
dir_window_down()
{
scroll_window_down(5,41,14,74);
}
/***********************************************************************/
/* */
/* Clear directory Window */
/* */
/***********************************************************************/
dir_window()
{
clear_window(5,41,14,74);
}
/***********************************************************************/
/* */
/* Clear the Text Window */
/* */
/***********************************************************************/
text_window()
{
clear_window(18,1,23,77);
}
/***********************************************************************/
/* */
/* Get a function character */
/* */
/***********************************************************************/
char getfch()
{
char i;
i = getcnenb();
if(i) return i;
else return -getcnenb();
}
/***********************************************************************/
/* */
/* Put string Unbuffered. */
/* */
/***********************************************************************/
putsnb(_str)
char *_str;
{
while(*_str) putcnb(*_str++);
}
/***********************************************************************/
/* */
/* DOS low-level Fucntions */
/* */
/***********************************************************************/
/***********************************************************************/
/* */
/* Get char unbuffered with echo. */
/* */
/***********************************************************************/
char getcnenb()
{
REGS.HREG.r_ah = 8;
REGS.HREG.r_al = 0;
REGS.HREG.r_bh = 0;
REGS.HREG.r_bl = 0;
REGS.HREG.r_ch = 0;
REGS.HREG.r_cl = 0;
REGS.HREG.r_dh = 0;
REGS.HREG.r_dl = 0;
intcall(®S,®S,0x21);
return REGS.WREG.r_ax & 0xff;
}
/***********************************************************************/
/* */
/* Has the keyboard been hit? */
/* */
/***********************************************************************/
kbhit()
{
REGS.HREG.r_ah = 0x0b;
intcall(®S,®S,0x21);
return (REGS.HREG.r_al!=0);
}
/***********************************************************************/
/* */
/* Set the cursor size. Good for Monochrome and Color */
/* */
/***********************************************************************/
setcsize(tscan,bscan)
int tscan,bscan;
{
REGS.HREG.r_ah = 0x1;
REGS.HREG.r_al = 0;
REGS.HREG.r_ch = tscan;
REGS.HREG.r_cl = bscan;
intcall(®S,®S,0x10);
}
/***********************************************************************/
/* */
/* Clear the Screen. */
/* */
/***********************************************************************/
cls()
{
clear_window(0,0,24,79);
}
/***********************************************************************/
/* */
/* Fill a window. */
/* */
/***********************************************************************/
fill_window(rch,rcl,rdh,rdl,attrib)
int rch,rcl,rdh,rdl,attrib;
{
REGS.HREG.r_ah = 6;
REGS.HREG.r_al = 0;
REGS.HREG.r_bh = attrib;
REGS.HREG.r_bl = 0;
REGS.HREG.r_ch = rch;
REGS.HREG.r_cl = rcl;
REGS.HREG.r_dh = rdh;
REGS.HREG.r_dl = rdl;
intcall(®S,®S,0x10);
}
/***********************************************************************/
/* */
/* Clear a window. */
/* */
/***********************************************************************/
clear_window(rch,rcl,rdh,rdl)
int rch,rcl,rdh,rdl;
{
REGS.HREG.r_ah = 6;
REGS.HREG.r_al = 0;
REGS.HREG.r_bh = 7;
REGS.HREG.r_bl = 0;
REGS.HREG.r_ch = rch;
REGS.HREG.r_cl = rcl;
REGS.HREG.r_dh = rdh;
REGS.HREG.r_dl = rdl;
intcall(®S,®S,0x10);
}
/***********************************************************************/
/* */
/* Scroll Window UP */
/* */
/***********************************************************************/
scroll_window_up(rch,rcl,rdh,rdl)
int rch,rcl,rdh,rdl;
{
REGS.HREG.r_ah = 6;
REGS.HREG.r_al = 1;
REGS.HREG.r_bh = 7;
REGS.HREG.r_bl = 0;
REGS.HREG.r_ch = rch;
REGS.HREG.r_cl = rcl;
REGS.HREG.r_dh = rdh;
REGS.HREG.r_dl = rdl;
intcall(®S,®S,0x10);
}
/***********************************************************************/
/* */
/* Scroll Window DOWN. */
/* */
/***********************************************************************/
scroll_window_down(rch,rcl,rdh,rdl)
int rch,rcl,rdh,rdl;
{
REGS.HREG.r_ah = 7;
REGS.HREG.r_al = 1;
REGS.HREG.r_bh = 7;
REGS.HREG.r_bl = 0;
REGS.HREG.r_ch = rch;
REGS.HREG.r_cl = rcl;
REGS.HREG.r_dh = rdh;
REGS.HREG.r_dl = rdl;
intcall(®S,®S,0x10);
}
/***********************************************************************/
/* */
/* Position the Cursor. */
/* */
/***********************************************************************/
locate(rr,cc)
int rr,cc;
{
REGS.HREG.r_ah = 2;
REGS.HREG.r_al = 0;
REGS.HREG.r_bh = 0;
REGS.HREG.r_bl = 0;
REGS.HREG.r_ch = 0;
REGS.HREG.r_cl = 0;
REGS.HREG.r_dh = rr;
REGS.HREG.r_dl = cc;
intcall(®S,®S,0x10);
}
/***********************************************************************/
/* */
/* Find the first occurance to match the given file name. */
/* */
/***********************************************************************/
dfind(find_struct,find_name,attrib)
struct FILEINFO *find_struct;
char *find_name;
int attrib;
{
thisattrib = attrib;
thisfile = find_name;
REGS.WREG.r_ax = SETDTA; /* set disk transfer to structure */
ptoreg(dsreg, REGS.WREG.r_dx, REGS.WREG.r_ds, find_struct);
intcall(®S, ®S, DOSINT);
REGS.WREG.r_ax = NFFIRST; /* FINDFIRST function */
REGS.WREG.r_cx = thisattrib; /* attributes set */
ptoreg(dsreg, REGS.WREG.r_dx, REGS.WREG.r_ds, thisfile);
intcall(®S, ®S, DOSINT); /* Find first */
if (REGS.WREG.r_flags & F_CF)
return FALSE; /* no matches found */
return TRUE;
}
/***********************************************************************/
/* */
/* Find the next occurance to match the given file name */
/* */
/***********************************************************************/
dnext(find_struct)
struct find *find_struct;
{
REGS.WREG.r_ax = SETDTA;
ptoreg(dsreg, REGS.WREG.r_dx, REGS.WREG.r_ds, find_struct);
intcall(®S, ®S, DOSINT);
REGS.WREG.r_ax = NFNEXT; /* FINDFIRST function */
REGS.WREG.r_cx = thisattrib; /* attributes set */
ptoreg(dsreg, REGS.WREG.r_dx, REGS.WREG.r_ds, thisfile);
intcall(®S, ®S, DOSINT); /* Find first */
if (REGS.WREG.r_flags & F_CF)
return FALSE; /* no more matches found */
return TRUE;
}
/***********************************************************************/
/* */
/* Get and dispaly the computer's time */
/* */
/***********************************************************************/
new_time()
{
static char ampm[5] = "a.m.";
REGS.HREG.r_ah = 0x2c;
REGS.HREG.r_al = 0;
intcall(®S, ®S, DOSINT);
nhour = REGS.HREG.r_ch;
if(nhour > 12)
{
nhour -= 12;
ampm[0] = 'p';
}
else {
if(nhour == 0)
nhour = 12;
ampm[0] = 'a';
}
nminute = REGS.HREG.r_cl;
nsecond = REGS.HREG.r_dh;
locate(1,60);
sprintf(temp,"%02d:%02d:%02d %s",nhour,nminute,nsecond,ampm);
putsnb(temp);
}
/***********************************************************************/
/* */
/* Get and dispaly the computer's date */
/* */
/***********************************************************************/
new_date()
{
REGS.HREG.r_ah = 0x2a;
REGS.HREG.r_al = 0;
intcall(®S, ®S, DOSINT);
nmonth = REGS.HREG.r_dh;
nday = REGS.HREG.r_dl;
nyear = REGS.WREG.r_cx - 1900;
locate(1,5);
sprintf(temp,"%02d/%02d/%02d",nmonth,nday ,nyear );
putsnb(temp);
}
/***********************************************************************/
/* */
/* Display the computer's date and time */
/* */
/***********************************************************************/
time_display()
{
new_time();
new_date();
}
/***********************************************************************/
/* */
/* Get the Current Drive */
/* */
/***********************************************************************/
current_drive()
{
REGS.HREG.r_ah = 0x19;
REGS.HREG.r_al = 0;
REGS.HREG.r_bh = 0;
REGS.HREG.r_bl = 0;
REGS.HREG.r_ch = 0;
REGS.HREG.r_cl = 0;
REGS.HREG.r_dh = 0;
REGS.HREG.r_dl = 0;
intcall(®S,®S,0x21);
}
/***********************************************************************/
/* */
/* Get the Current Path */
/* */
/***********************************************************************/
getpath()
{
ptoreg(dsreg, REGS.WREG.r_dx, REGS.WREG.r_ds,temp);
REGS.HREG.r_ah = 0x47;
REGS.HREG.r_al = 0;
REGS.HREG.r_dh = 0;
REGS.HREG.r_dl = 0;
REGS.HREG.r_ch = 0;
REGS.HREG.r_cl = 0;
REGS.HREG.r_bh = 0;
REGS.HREG.r_bl = 0;
intcall(®S,®S,0x21);
}
/***********************************************************************/
/* */
/* Make a new Subdirectory */
/* */
/***********************************************************************/
mkdir(newdir)
char *newdir;
{
ptoreg(dsreg, REGS.WREG.r_dx, REGS.WREG.r_ds,newdir);
REGS.HREG.r_ah = 0x39;
REGS.HREG.r_al = 0;
intcall(®S,®S,0x21);
}
/***********************************************************************/
/* */
/* Change Sub-directory */
/* */
/***********************************************************************/
chdir(newdir)
char *newdir;
{
ptoreg(dsreg, REGS.WREG.r_dx, REGS.WREG.r_ds,newdir);
REGS.HREG.r_ah = 0x3b;
REGS.HREG.r_al = 0;
intcall(®S,®S,0x21);
get_directory(last_dir_format);
display_contents();
}
/***********************************************************************/
/* */
/* Remove a SubDirectory */
/* */
/***********************************************************************/
rmdir(newdir)
char *newdir;
{
ptoreg(dsreg, REGS.WREG.r_dx, REGS.WREG.r_ds,newdir);
REGS.HREG.r_ah = 0x3a;
REGS.HREG.r_al = 0;
intcall(®S,®S,0x21);
}
/***********************************************************************/
/* */
/* Change Logged Drive */
/* */
/***********************************************************************/
chdrive(newdrv)
char *newdrv;
{
REGS.HREG.r_ah = 0x0e;
REGS.HREG.r_al = 0;
REGS.HREG.r_dl = toupper(*newdrv) - 'A';
intcall(®S,®S,0x21);
getpath();
locate(19,15);
putsnb("Current Path : ");
putsnb((char*)REGS.WREG.r_si);
infowindow();
get_directory(last_dir_format);
display_directory();
}
/***********************************************************************/
/* */
/* Get Disk Space */
/* */
/***********************************************************************/
disk_space()
{
REGS.HREG.r_ah = 0x36;
REGS.HREG.r_al = 0;
REGS.HREG.r_dl = 0;
REGS.HREG.r_dh = 0;
intcall(®S,®S,0x21);
free_space = REGS.WREG.r_cx;
free_space *= REGS.WREG.r_ax;
free_space *= REGS.WREG.r_bx;
disk_size = REGS.WREG.r_cx;
disk_size *= REGS.WREG.r_ax;
disk_size *= REGS.WREG.r_dx;
disk_slack =(REGS.WREG.r_bx * 100) / REGS.WREG.r_dx;
}